Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TUT] Include mySQL into php.
#11
No offense but it is great to be able to open a certain database and connect to it but you both are forgetting that the connection should be closed as well.

http://se2.php.net/manual/en/function.mysql-close.php

More information on the use of MySQL in combination with PHP.

http://se2.php.net/manual/en/book.mysql.php
Reply
#12
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.
[Completely Honest. Seriously.]

Protip: Anonymous Reputation Points are for Pussies
Reply
#13
Thanks for linking to my thread!

Reply
#14
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
Reply
#15
(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. Tongue
Reply
#16
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
Reply
#17
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"
Reply
#18
(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.
Reply
#19
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..!
Reply
#20
(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 .!!!Yeye
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  vb6.0 + mysql Anurag.91 1 1,792 09-08-2012, 04:19 PM
Last Post: spesificrelax
  Creating and inserting data into a PHP and MySQL Database Peter L 9 4,644 03-24-2012, 10:49 AM
Last Post: Haxalot
  VB.NET MySql , Help please booterphhp 2 1,875 03-19-2012, 11:13 AM
Last Post: RainbowDashFTW
  MySQL (Innodb vs MyISAM) Omniscient 15 10,758 07-22-2011, 03:15 PM
Last Post: developer99
  MySQL question ImFocuzz 8 3,148 07-17-2011, 06:57 PM
Last Post: Pedo bear

Forum Jump:


Users browsing this thread: 2 Guest(s)