Not really, MySQL connections are automatically closed by the PHP garbage collection bullshit, it doesn't hurt to close the connection but ever since PHP4 it has been done automatically, so I see no point.
Thanks for linking to my thread!
Also to avoid exceptions to be trow en you need to use
try catch finally commands while executing query on the mysql database
example
if you want to make update query and user forgot to enter value for the set something='.var.'
then exception will be trown so you should use this command structure
Code:
<?php
try {
$s = mysql_query('Update ...... set..... Select or anything');
}
catch (MyException $e){
echo $e;
}
finaly {
echo 'query executed succesfully';
}
?>
here is more info about php exceptions and how to use them for anything not just for mysql
http://php.net/manual/en/language.exceptions.php
(10-05-2009, 05:30 PM)xiofire Wrote: [ -> ]Hmm... Shorthand? Yuck.
Heres how I connect to my databases
Code:
<?php
class connection {
private $database, $connect;
function connect() {
$this->database = array(
'username' => 'USERNAME',
'password' => 'PASSWORD',
'host' => 'localhost',
'name' => 'DATABASE NAME'
);
$this->connect = mysql_connect($this->database['host'], $this->database['username'], $this->database['password']);
mysql_select_db($this->database['name'], $this->connect);
}
}
$db = new connection();
$db->connect();
?>
hopefully you have more than the one function in your class. It has such great potential.
i m new to php, i m using wamp server ,i dont know how to config php apachi and mysql that's y i used wamp. i 'm still tring ur code
i got these erros
Warning: include(settings.inc.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\ABC\database.php on line 8
Warning: include() [function.include]: Failed opening 'settings.inc.php' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\ABC\database.php on line 8
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\ABC\database.php on line 9
Could not establish a connection with mysql
in wamp it didnt ask a password. plz help me
It's obivious, the file settings.inc.php doesn't exist at the path you're including it from...
PHP Code:
include "full_path_to_your_file";
(01-15-2010, 10:50 AM)Master of The Universe Wrote: [ -> ]It's obivious, the file settings.inc.php doesn't exist at the path you're including it from...
PHP Code:
include "full_path_to_your_file";
i search on wamp folder but i didnt see any file called settings.inc.php.
so where do i set the path,and when i intall the wamp it didnt ask any user name and password,so how do i find mysql user name and password so what should i do to the user name and password .i m new to php.
Wamp's default setting for database user is, Username: root, Password: BLANK
You can access it over here
http://localhost/phpmyadmin
There you will nt be asked for username and password....
When you use mysql_connect() on WAMP you would call it like this;
PHP Code:
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
When you use this inside of index.php
Code:
include "settings.inc.php";
The code will include a file with the name "settings.inc.php" from the same directory where your index.php file is...
If you place the file into a folder named "conf" the line would look like this.
PHP Code:
include "conf/settings.inc.php";
You need to create a settings.inc.php file..!
(01-16-2010, 08:28 PM)Master of The Universe Wrote: [ -> ]Wamp's default setting for database user is, Username: root, Password: BLANK
You can access it over here http://localhost/phpmyadmin
There you will nt be asked for username and password....
When you use mysql_connect() on WAMP you would call it like this;
PHP Code:
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
When you use this inside of index.php
Code:
include "settings.inc.php";
The code will include a file with the name "settings.inc.php" from the same directory where your index.php file is...
If you place the file into a folder named "conf" the line would look like this.
PHP Code:
include "conf/settings.inc.php";
You need to create a settings.inc.php file..!
ohh yess , thanks a lot friend i m relly happy , i just connect it,this is my first time,Thanks a lot again and again .!!!