Obtain all of the columns from sql server using php in one command? -
is there way data sql server table. trying acheive have sql table 5 columns. have x amount of entries, of them have x amount. example 5 columns have a,b,c,d,e. of them have 10 entries or 20 entries.
now know how run query 1 of them
$servername = "server"; //servername\instancename $connectioninfo = array( "database"=>"db", "uid"=>"u/n", "pwd"=>"pass"); $conn = sqlsrv_connect( $servername, $connectioninfo); $sql = "select table"; $query = sqlsrv_query($conn, $sql); if ($query === false){ echo "could not link sql server"; } $i = 0; while ($row = sqlsrv_fetch_array($query)) { $a[$i] = "$row[a]"; $i++; } sqlsrv_free_stmt($query); sqlsrv_close( $conn );
so in code values of column , stored in $a array of length $i. question can (and if yes how), column @ once without copying code. know
$sql = "select * table";
but after that?
wouldn't work?
$servername = "server"; //servername\instancename $connectioninfo = array( "database"=>"db", "uid"=>"u/n", "pwd"=>"pass"); $conn = sqlsrv_connect( $servername, $connectioninfo); $sql = "select * table"; //change select * in sql $query = sqlsrv_query($conn, $sql); if ($query === false){ echo "could not link sql server"; } $i = 0; while ($row = sqlsrv_fetch_array($query)) { $a[$i] = "$row[a]"; $b[$i] = "$row[b]"; $c[$i] = "$row[c]"; //add rest of columns $i++; } sqlsrv_free_stmt($query); sqlsrv_close( $conn );
Comments
Post a Comment