Re: Please help newbie php / mysql

From: Date: Tue, 22 Apr 2003 05:25:52 +0000
Subject: Re: Please help newbie php / mysql
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19544@lists.php.net to get a copy of this message
> Hi, > > I'm currently learning php and mysql, i have installed the latest version of > Apache (2.0.45) and the PHP (4.3.1) and mysql, on windows XP pro. Is Apache 2 playing friendly with php yet? Or was that PEAR? Anyway, I know the mail volume is overwhelming, but I suggest you set up filters in your e-mail browser and get on the MySQL main and windows lists. > I am able to display the status of the MySQL database using a php script > that displays the results in a browser. But I can't submit a query to the > database to create a new table, I am able to create the table using the SQL > dialog in the MySQL manager. So I know that there is not a problem with the > syntax of my SQL, I'm using the same connection as used for the status > display script and I know the query I type into the form is being parsed as > I display it as soon as the script starts. Can't say much without looking at your code, but I'll go ahead and post some dead-simple code I've been using for testing. ('webUserName' is not my real web user name, and 'webUserPassword' is not the real password, of course. Likewise, webDB and webTable.) ----------------------mysql example-------------------- <?php $dbResource = mysql_connect( 'localhost', 'webUserName', 'webUserPassword' ); if ( $dbResource == FALSE ) { echo( "where is it?<br />\n" ); } else { echo( "Found the thing!<br />\n" ); $dbOpened = mysql_select_db( 'webDB', $dbResource ); if ( ! $dbOpened ) { echo( "What was it?<br />\n" ); } else { echo( "We have data!<br />\n" ); $queryResource = mysql_query( 'select * from webTable', $dbResource ); if ( $queryResource == FALSE ) { echo( "why isn't it listening?<br />\n" ); } else { echo( "successful query, results follow:<br />\n" ); for ( ;; ) { $resultRow = mysql_fetch_array( $queryResource, MYSQL_BOTH ); if ( $resultRow == FALSE ) { break; } foreach ( $resultRow as $fieldName => $fieldValue ) { echo( "$fieldName: $fieldValue<br />\n" ); } } } } mysql_close( $dbResource ); } ?> --------------------end mysql example------------------ ----------------------pear example--------------------- <?php require_once 'DB.php'; // $dsn = "$dbType://$user:$pass@$host/$db_name"; $dbType = 'mysql'; $dataSourceName = "$dbType://webUserName:webUserPassword@localhost/webDB"; $dbConnection = DB::connect( $dataSourceName, TRUE ); // TRUE => persistent connection if ( DB::isError( $dbConnection ) ) { echo( "$dbConnection->getMessage()<br />So where is it?<br />\n" ); } else { echo( "Found the thing!<br />\n" ); $queryResult = $dbConnection->query( 'select * from webTable' ); if ( DB::isError( $queryResult ) ) { echo( "why isn't it listening?<br />\n" ); } else { echo( "successful query, results follow:<br />\n" ); for ( ;; ) { $resultRow = $queryResult->fetchRow(); if ( $resultRow == NULL || DB::isError( $resultRow ) ) { if ( $resultRow != NULL ) { echo( "Problems getting the next row!<br />\n" ); } break; } foreach ( $resultRow as $fieldName => $fieldValue ) { echo( "$fieldName: $fieldValue<br />\n" ); } } } $dbConnection->disconnect(); } ?> --------------------end pear example------------------- IIRC, I've got a flaky test in the PEAR example, but it works for me right now anyway. (You can change $dbType and $dataSourceName in the PEAR example appropriately and use the PEAR example to access PostGreSQL as well.) -- Joel Rees <joel@alpsgiken.gr.jp>

« previous php.windows (#19544) next »