开发者

PHP/SQL Testing Environment

Hey, a beginner's question here.... In order to learn PHP and SQl I have set up a Localhost Server on my computer running Apache and phpmyadmin, using MAMP.

In the course of testing, I have found that through the backend phpmyadmin interface I can modify the db as I please without any trouble. However, when I try to query the db through php scripts, no changes seem to be committed.

I say this because it seems that I am able to open a connection to phpmyadmin, evident by the error messages I receive when trying to pass a malformed query.

When I run these scripts, and then check the backend, I see no changes even though I received no errors.

My best guess would be php is incorrect. So here is what I am using.开发者_如何学C

<?php
$connect = mysql_connect("localhost", "roo", "root");
if(!$connect){
    die('COULD NOT CONNECT! HURS WHY : ' . mysql_error());
    }
echo "Connection Success";

mysql_select_db("Geodb", $connect);

mysql_query("INSERT INTO countries (country_code, country_name)
VALUES ('uk', 'United Kingdom')");

mysql_close($connect);
?>

I suspect that this has been a problem because i am a beginner, but I have tried solving it and searched for an answer... So I hope you won't mind helping me out haha.

Thanks


Chances are that an error is being thrown, but not displayed due to your display_errors php.ini setting. As such, I'd recommend checking your error logs.

Additionally, as this isn't a production environment (and hence it's OK to show errors) you'll probably want to change your display_errors setting to on (display_errors = On) and your error_reporting level to...

error_reporting = E_ALL & ~E_NOTICE

or, better still...

error_reporting = E_ALL

...within your php.ini file.

By doing this, you'll be informed of all the errors, warnings and notices that are occurring.


The problem may be happening when you select the database. What you can do is:

if(!mysql_select_db("Geodb", $connect))
  die ("Couldn't find the db".mysql_error());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜