|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
Hey all;
I'm one of those newbies to the PHP realm of programming and I've run into a stumper. What I'm trying to do is pull data (any data at this point) from a mysql database. I've checked and doublechecked by my code and cross referenced examples on the Web, but I cannot seem to find anything that might give me some incite. Below is a code snippet showing what I'm trying to accomplish. <?php $connection = mysql_connect('localhost', 'user', 'pass'); if(!$connection) { die ("Could not connect to the database: \n". mysql_error()); } elseif($connection) { print "Successfully connected to the database \n"; } $db_select = mysql_select_db('self_serv'); if(!$db_select) { die ("Could not select the database: \n". mysql_error()); } elseif($db_select) { print "Successfully selected the database \n"; } $select = 'SELECT'; $column = '*'; $from = 'FROM'; $tables = 'app_n_port'; $where = 'WHERE app_no=1001'; $query = $select." ".$column." ".$from." ".$tables." ".$where. " LIMIT 0, 30"; $result = mysql_query($query); if (!$result); { die ("Query failed. Your Query: " . $query . " Returned Error Number: " ." ".mysql_errno() . " Error Detail-> " . m ysql_error()). "\n"; } while ($result_row = mysql_fetch_array($result)) { echo $result_row. "\n"; } mysql_close($connection); ?> After running the script I get the "die" statement after the <if(! $result) clause with no mysql_error and a mysql_errno of 0. Any would be greatly appreciated. Thanks in advance, Thad |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
On Fri, 14 Sep 2007 19:58:25 -0000, thad.irvin@gmail.com wrote:
>if (!$result); You have a semicolon here, ending the statement. > { This brace is not connected to the previous conditional. Despite PHP not doing block scoping, it does let you put redundant braces around blocks. > die ("Query failed. Your Query: " . $query . " >Returned Error Number: " ." ".mysql_errno() . " Error Detail-> " . m >ysql_error()). "\n"; So this always runs, $result probably was valid, and mysql_errno tells you "no there wasn't an error". -- Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool |
|
![]() |
| Outils de la discussion | |
|
|