Fetch array mysql database php -


i trying fetch data database, not working.

this code:

<?php  $koppla = mysql_connect("localhost","admin","","test");    // check connection   if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }       $get = mysql_query($koppla,select * 123);  while ($test = mysql_fetch_array($get)) {     echo $test['tid']; }  mysql_close($koppla); ?> `<?php  $koppla = mysql_connect("localhost","admin","","test");    // check connection   if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }       $get = mysql_query($koppla,select * 123);  while ($test = mysql_fetch_array($get)) {     echo $test['tid']; }  mysql_close($koppla); ?> 

i getting following error while trying fetch array mysql database. wrong?

parse error: syntax error, unexpected '123' (t_lnumber) in c:\wamp\www\test.php on line 16 

what wrong

there @ least 3 errors:

  • use either mysql_xy or mysqli_xy. not both. see mysql: choosing api.
    tl;dr: use mysqli_*, because mysql_* deprecated.
  • the select statement in line 16 , line 39 has in quotes.
  • the syntax of mysql_query is

    mixed mysql_query ( string $query [, resource $link_identifier = null ] )

what correct

so line 16 has like

$get = mysql_query("select * 123", $koppla); 

or, when choose mysqli_query:

$get = mysqli_query($koppla, "select * 123"); 

side notes

  • table naming: not use table name 123. don't know if valid sql, feels wrong not start table character. see sqlite issue table names using numbers? - know you're using mysql, mysql might have similar problems. , might want switch database system.
  • optional arguments: don't need specify $link_identifier in mysql_* if don't have multiple connections.
  • style guide: in php, have curly brace { in same line if. see list of highly-regarded php style guides? , zend , pear section. so, because avoid scrollbar in code makes reading question easier.

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -