Stats: 3,190,975 members, 7,942,485 topics. Date: Saturday, 07 September 2024 at 11:01 AM |
Nairaland Forum / Science/Technology / Programming / Help. Mysql Function Returning Booleans Instead Of Resourse (1195 Views)
Contest[closed] : Program A Function to find if a phrase. is in a string / Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql / DHTMLSQL - A Very Advanced Wrapper For Mysql Database! (2) (3) (4)
Help. Mysql Function Returning Booleans Instead Of Resourse by Thirdwrist(m): 5:26pm On Jan 21, 2016 |
I have bee learning PHP for some time now, and covered a little ground in it. But all that has been in procedual style. So I decided to delve into OOP it being the most secure of both and more organized. Here is my problem: <?php class connect{ public $db_host= "localhost"; public $username=""; public $password= ""; public $db_name=""; public $dbc; function db_connect(){ try{ $this->dbc= new PDO("mysql:host=$this->db_host; dbname=$this->db_name", $this->username, $this->password); mysql_select_db($this->db_name); } catch (PDOException $e){ echo "failed to connect to database pdo "; echo $e->getmessage(); exit(); } return $this->dbc; } public $sql, $row, $result; public function tester(){ if(mysql_connect()) { $this->result=mysql_query("SELECT email FROM users WHERE id =1" ![]() $this->row=mysql_fetch_row($this->result); $this->sql=$this->row['email']; } else{ $this->sql= "bah quannection"; } return $this->sql; } } $connection = new connect(); $connection->db_connect(); echo "you are an OOP genius"; $connection->tester(); echo $connection->sql; ?> and it keeps outputting " you are an OOP genius Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Experiments\gstosa\index.php on line 29 |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by sinequanon: 6:26pm On Jan 21, 2016 |
Warning? Why don't you ask it if it is a genius, too? ![]() I am not a mysql programmer, but I suggest that your SELECT statement is failing. This could be because the correct schema containing your table has not been specified, the connected user does not have authority to the table, the table name or a field has been misspelled, or id is alphanumeric. You may want to call something like mysqli_error() or mysql_error() ?? to display what the error is. 1 Like |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by Nobody: 6:30pm On Jan 21, 2016 |
you are mixing mysql and pdo functions, it doesn't work that way 1 Like |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by sinequanon: 6:39pm On Jan 21, 2016 |
Jregz: When will folk stop saying "it doesn't work that way"!! ![]() More explanation please. It seems to me that the connection is successful, because the program gets to the point row=mysql_fetch_row, and it is complaining that the wrong parameter has been passed. This would appear to be because the SELECT has failed and is returning FALSE instead of a result set. 2 Likes |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by Thirdwrist(m): 6:40pm On Jan 21, 2016 |
Jregz:how then do I change that to pdo? |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by Nobody: 8:02pm On Jan 21, 2016 |
sinequanon: that was the answer to his problem, he connected with pdo and is trying to fetch data with myqsl* functions that he hasn't connected with, the place where he used mysql_connect should have his credentials, the way he checked for mysql_connect would only check if the function is available, nothing more 1 Like |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by maekhel(m): 9:05pm On Jan 21, 2016 |
Jregz got here before me. That's what I would have said. mixing mysql and pdo functions is bad practice and should never be encouraged. |
Re: Help. Mysql Function Returning Booleans Instead Of Resourse by maekhel(m): 9:37pm On Jan 21, 2016 |
Thirdwrist:I have updated your code
Note the updated code is not tested. |
(1) (Reply)
closed / Reasons Why Many Programmers Don't Get Jobs. / They Want To Send Me Back To My Village
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22 |