I've been reading through part IV of your tutorial, and I'm unclear about connecting PHP and MySQL. I followed the MySQL section fine, and the PHP section was OK, but I don't think I have the directories structured correctly for PHP to connect to MySQL. Where should I place the MySQL and PHP directories in relation to "http://localhost"?
Also the php.ini file specifies a doc_root of c:\sambar is this correct or should it be c:\sambar\docs, as this is where I run the .php scripts from?
Great article! I have a question though. Could you use "OR DIE()" rather than the if(!$db)?
For example, is it possible to do the following:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
$db = @mysqL_connect("host","login","password) or die("Cannot Connect:" . mysql_error());
[/code]
?
Thanks
Great article Kevin! After last week's article I got all anxious and found something on WebMonkey to allow me to do basically what you did, but it ended up being a great idea, it introduced me to some of those commands a bit early, so I found it much easier to follow along! What's the next article set to be about? The template system?
The doc_root is the folder you'll be accessing if you go to http://localhost/ in your browser.
Also MySQL doesn't need to be in the doc root, in fact it is VERY insecure if it is. That means anyone can read your databases. Just leave them wherever they are, like C:\mysql\data\ .
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote/font><HR>I followed the MySQL section fine, and the PHP section was OK, but I don't think I have the directories structured correctly for PHP to connect to MySQL. Where should I place the MySQL and PHP directories in relation to "http://localhost"?
Also the php.ini file specifies a doc_root of c:\sambar is this correct or should it be c:\sambar\docs, as this is where I run the .php scripts from?<HR></BLOCKQUOTE>
The MySQL and PHP directories may be placed anywhere on your hard drive. As d3v points out, these should really not be placed anywhere near the Web server's document directory. Your Web server communicates with PHP with its "plug-in" interface (ISAPI, in the case of Sambar Server), and PHP communicates with the MySQL server over TCP/IP. As long as the MySQL server is running, PHP should be able to connect to it. Let me know if this is not the case!
Indeed, your doc_root should be set to c:\sambar\docs (although this is not a huge deal).
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote/font><HR>
Great article! I have a question though. Could you use "OR DIE()" rather than the if(!$db)?
<HR></BLOCKQUOTE>
Yup, you can use that if you prefer. I stuck with an "if" statement because it was easier to explain. I may present the "OR <function>" trick in a later article if it proves appropriate.
Bookmarks