Forum Moderators: open
<?php
$mysql_host = "localhost";
$mysql_user = "username";
$mysql_pass = "password";
$mysql_db = "database";
$mysql_access = mysql_pconnect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db, $mysql_access);
?>
Then near the middle of the page, amongst all the html I have:
<?php
mysql_query("INSERT INTO search SET q='" . $q . "'", $mysql_access);
?>
And finally, at the very bottom after the end html tag, I have:
<?php
mysql_close($mysql_access);
?>
Now, I have no idea if this is a good way of doing it or not, i'm new to setting up this kind of stuff. I do know it works because the test query being searched is being inserted into the database. Being a search page and all, it will generate a lot of traffic so I don't want to kill the server because of my poor coding :P
Is this the most efficient way of opening a database? Any help much appreciated.
$mysql_host = "localhost";
$mysql_user = "username";
$mysql_pass = "password";
$mysql_db = "database";
$mysql_access = mysql_pconnect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db, $mysql_access);
Unless you intend to re-use them, there is no need to create all those variables. They only take up memory space. This should do:
$mysql_access = mysql_pconnect('localhost', 'username', 'password');
mysql_select_db('database', $mysql_access);
Note the use of single quotes: they require less processing power as the parser will not search single-quoted strings for variables. No one will notice, but everything helps...
Note the use of single quotes: they require less processing power as the parser will not search single-quoted strings for variables. No one will notice, but everything helps...
I didn't even know this! I have a very large site where I am using double quotes in some of my code, so thanks for the tip.
I didn't even know this! I have a very large site where I am using double quotes in some of my code, so thanks for the tip.
Always check the documentation [us2.php.net] for more details ;)