Jan 8, 2004 #1 TheConeHead Programmer Joined Aug 14, 2002 Messages 2,106 Location US Can anyone provide me with a sample connection string and query? I am working within PHP and am familiar with SQL (not My SQL) Thanks!
Can anyone provide me with a sample connection string and query? I am working within PHP and am familiar with SQL (not My SQL) Thanks!
Jan 8, 2004 1 #2 tshot Technical User Joined Jan 19, 2003 Messages 216 Location IN Code: <?php # sample connection query $link = mysql_connect('ServerNameOfMySql', 'MyLoginnameForMySql', 'MyPasswdForMySql') ; if ($link && mysql_db_select_db("samp_db") { $qry = 'SELECT * FROM MyTbl' ; $result = mysql_query($qry) or die("Sorry Query failed"); while ($row = mysql_fetch_row($result)) { for ($i = 0; $i < mysql_num_fields($result); $i++) { if ($i > 0) print("\t") ; print($row[$i]) ; } print("\n") ; } } mysql_free_result($result) ; ?> ---------------- ur feedback is a very welcome desire Upvote 0 Downvote
Code: <?php # sample connection query $link = mysql_connect('ServerNameOfMySql', 'MyLoginnameForMySql', 'MyPasswdForMySql') ; if ($link && mysql_db_select_db("samp_db") { $qry = 'SELECT * FROM MyTbl' ; $result = mysql_query($qry) or die("Sorry Query failed"); while ($row = mysql_fetch_row($result)) { for ($i = 0; $i < mysql_num_fields($result); $i++) { if ($i > 0) print("\t") ; print($row[$i]) ; } print("\n") ; } } mysql_free_result($result) ; ?> ---------------- ur feedback is a very welcome desire
Jan 8, 2004 Thread starter #3 TheConeHead Programmer Joined Aug 14, 2002 Messages 2,106 Location US excellent thanks.... When I use sql, I can grab specific field values like: rs("fieldValue".... how would I do so throughout a php page? You can do more than simply loop through it right? Upvote 0 Downvote
excellent thanks.... When I use sql, I can grab specific field values like: rs("fieldValue".... how would I do so throughout a php page? You can do more than simply loop through it right?
Jan 8, 2004 #4 tshot Technical User Joined Jan 19, 2003 Messages 216 Location IN chnage qry to Code: $qry = 'SELECT Fld1, Fld2, Fld3 FROM MyTbl' ; Besides, mysql_fetch_row, another option mysql_fetch_array can be used. Herw u have to substitiute fld name in place of no subscripts i.e. for Code: $qry = 'SELECT FirstName, Lastname FROM Names' ; $result = mysql_query($result) or die() ; while ($row = mysql_fetch_array($result)) { printf("%s %s\n", $row[0], $row[1]) ; printf("%s %s\n", $row['FirstName'], $row['Lastname']) ; } Thing 2 note is that subscript names have identical spelling including case as in SELECT option i.e name in Lastname is all lower case ---------------- ur feedback is a very welcome desire Upvote 0 Downvote
chnage qry to Code: $qry = 'SELECT Fld1, Fld2, Fld3 FROM MyTbl' ; Besides, mysql_fetch_row, another option mysql_fetch_array can be used. Herw u have to substitiute fld name in place of no subscripts i.e. for Code: $qry = 'SELECT FirstName, Lastname FROM Names' ; $result = mysql_query($result) or die() ; while ($row = mysql_fetch_array($result)) { printf("%s %s\n", $row[0], $row[1]) ; printf("%s %s\n", $row['FirstName'], $row['Lastname']) ; } Thing 2 note is that subscript names have identical spelling including case as in SELECT option i.e name in Lastname is all lower case ---------------- ur feedback is a very welcome desire
Jan 8, 2004 Thread starter #5 TheConeHead Programmer Joined Aug 14, 2002 Messages 2,106 Location US excellent... that gives me plenty to look into... thanks Upvote 0 Downvote