How to get all parameters in MSSQL Stored Procedure [duplicate] - php

This question already has answers here:
Find the parameter names of a stored procedure
(3 answers)
Closed 8 years ago.
When I was using asp, I was able to do the following - now I am using php and sqlsrv - how do I achieve the same in php
Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = "dbo.spGetItem"
oCmd.CommandType = &H0004 'adCmdStoredProc
oCmd.Parameters.Refresh
For Each prmTemp In oCmd.Parameters
Response.Write( prmTemp.direction & "<br/>" & prmTemp.name)
Next
Set oCmd = Nothing

The simplest way regardless of client language is to just query the metadata / catalog views:
SELECT name, is_output
FROM sys.parameters
WHERE [object_id] = OBJECT_ID('dbo.spGetItem');

select ORDINAL_POSITION, PARAMETER_NAME, DATA_TYPE, PARAMETER_MODE from information_schema.parameters
where specific_name='Proc_Name'

Related

Faster way to fetch a single data from db with codeigniter [duplicate]

This question already has answers here:
getting the value of the single field output using the codeigniter active record
(5 answers)
Closed 2 years ago.
hi want to get only one column from one result from my database. So i do it in this way
$this->db->select('myclolumn')->where('id',$id);
$query = $this->db->get('mytable');
$temp=$query->row_array();
$finalresult=$temp['mycolumn'];
Maybe there is a easier or faster way to do the same?
so based on DanishAli's comment
$this->db->select('myclolumn')->where('id',$id);
$query = $this->db->get('mytable');
$finalresult=$query->row()->mycloumn;
You can do it like this:
$finalresult = $this->db->select('myclolumn')
->where('id',$id)
->get('mytable')->row()
->mycolumn;
All in only one command instead of a lot of variables and extra code.
In case you need to provide a default value if the row is null, break the command to:
$row = $this->db->select('myclolumn')
->where('id',$id)
->get('mytable')
->row();
$finalresult = ($row)?$row->mycolumn:'your default value';

Get count of Referer domain from users Database [duplicate]

This question already has an answer here:
Group by substring
(1 answer)
Closed 4 years ago.
how can i get count of all domain from users from database
example:
id user refurl
1 ultraman https://google.com/asd/a3sd/asd.html
2 Kingogthe https://google.be/asd/as2d/asd.html
3 biomanliv https://google.ttr/asd/a1sd/asd.html
4 amanrras https://google.mmo/asd/a4sd/asd.html
5 talllos https://yahoo.cosdm/asd/a5sd/asd.html
6 bicenoza https://yahoo.gd/asd/as6d/asd.html
7 Linliveagi https://www.bing.cp/asd/as6d/asd.html.
8 fkbareshuy https://www.bing.cdd/asd/as6d/asd.html
The output to be like:
4 from google
2 from yahoo
2 from bing
etc.
I tried "SELECT COUNT(*) ......" but didn't work how i wanted to
and i tried to use parse_url['host']
$url = parse_url['host'];
$getdomainonly = explode('.',$url);
echo $getdomainonly[0];
//here you get domain without com net Example: https://google.com/asd/aasd to only google
but i don't know how to use this php code with SQL to get the output
if you want to know:
I run script on php 5.6 but i can change it if there is answer for 7.0,7.1 or 7.2
I use MySql to saved data
Because you have tagged php, I'm going to guess that you are using MySQL. If so, you can do:
select substring_index(substring_index(refurl, '.', 1), '//', -1) as domain,
count(*)
from example
group by domain;

How do you correctly handle the hash/pound/number (#) sign in php/mysql? [duplicate]

This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
How can I accept a hash mark in a URL via $_GET?
(4 answers)
Closed 4 years ago.
I have this website where users can enter stable names to compete in games against other members. Usually it's fine as I can just escape or use addslashes to handle apostrophes and other such characters. What I am having an issue with is when users use a hash/pound/number sign in the stable name like the first example below or a bunch of special characters like the second example below...
#a new rising
ΔMi−1 = −αΣn=1NDi[n][Σj∈C{i}Fji[n - 1] + Fexti[[n-1]]
When this goes over as part of a url to a second page and the stable is a appended to the URL to be used as a GET variable to pull details from the database, nothing is returned. I have tried using urlencode, rawurlencode, and percent encoding on the $stable variable as is suggested in other questions on this site but nothing seems to work. Below is a sample of the code that has the issue...
Referring URL --- mydomain.com/stable.php?stable=#a new rising&season=59
Code for stable.php...
$stable = addslashes($_GET["stable"]);
$season = $_GET['season'];
echo $stable;
$sql = "SELECT total, wins, loss, ties FROM History_Stables WHERE stable = '$stable' AND season = '$season'";
$res = $link->query($sql);
$arr = $res->fetch_array();
$pts = $arr[total];
$w = $arr[wins];
$l = $arr[loss];
$t = $arr[ties];
And so on. What exactly am I missing here to get the hash/pound/number sign to be properly encoded as %23?

how to find who is department head of employee USING IN CLAUSE in php [duplicate]

This question already has answers here:
Passing an array to a query using a WHERE clause
(17 answers)
Closed 6 years ago.
$department_id=19
$deptshead(17,19,3)
$sql_depthead ="SELECT * FROM nonaudit_employee WHERE status = 'Active' AND rights = 3 AND deptshead IN(".$department.")AND cand_id!= ".$cand_id;
its working fine but
it only match first dept head cant check the second dept value???
I'm not sure if I correct understood.
You can try to use:
$inClause = implode(",", $deptshead);
And after that use $inClause var in your query

How to use WHERE - LIKE cluase in yii2 and make LIKE pattern search with case sensitivity? [duplicate]

This question already has answers here:
How can I make SQL case sensitive string comparison on MySQL?
(12 answers)
Closed 6 years ago.
$aa = India::find();
$players = $aa
->where('player LIKE :query', [':query'=>'S%'])
->orderBy('position, player')->all();
$countnumber = $aa->count();
This code returns results without case sensitivity.
Gives results where Player name starts with 'S' or 's'.
But I want to make, just to select Player names only with 'S'.
How to restrict it to select with case sensitivity in PHP Yii2 Framworok ?
In case you are using MySQL you can make your query with BINARY
So your Yii2 code should be something like this:
$players = India::find()
->where(['LIKE BINARY', 'player', $query_parameter])
->orderBy('position, player')->all();

Categories