Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15238 > unrolled thread
| Started by | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| First post | 2015-04-11 16:18 -0700 |
| Last post | 2015-04-13 12:48 -0700 |
| Articles | 11 — 2 participants |
Back to article view | Back to comp.lang.php
PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-11 16:18 -0700
Re: PDO problem Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-11 19:58 -0400
Re: PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-11 17:12 -0700
Re: PDO problem Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-11 20:17 -0400
Re: PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-11 17:24 -0700
Re: PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-11 17:26 -0700
Re: PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-12 06:01 -0700
Re: PDO problem Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-12 12:40 -0400
Re: PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-12 10:03 -0700
Re: PDO problem Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-12 16:34 -0400
Re: PDO problem Hiago Vitor <hiagoiuri@gmail.com> - 2015-04-13 12:48 -0700
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-11 16:18 -0700 |
| Subject | PDO problem |
| Message-ID | <865189d4-1ef8-4aca-a619-13b59009061a@googlegroups.com> |
//-----------------index.php---------------------------------
<?php
include 'db.php';
include 'config.php';
$Data = new DataBase($database);
//$Data = new DataBase($host,$dbname,$port,$user,$password);
$Data->email = 'testes$gmail.com';
$Data->senha = 'teste5';
echo $Data->getHost().'<br>';
echo $Data->getDbname().'<br>';
echo $Data->getPort().'<br>';
echo $Data->getUser().'<br>';
echo $Data->getPassword().'<br>';
$Data->connect();
$email='lalaal@gmail.com';
$pwd='lalalalalala';
$Data->insert($email,$pwd);
?>
//-------------------------------db.php--------------------------------
<?php
class DataBase{
public $email;
public $senha;
public $host;
public $dbname;
public $port;
public $user;
public $password;
//var $type;
public function __construct($database){
self::setHost($database['host']);
self::setDbname($database['name']);
self::setPort($database['port']);
self::setUser($database['user']);
self::setPassword($database['pass']);
//---- self::set_type($database['type']);
}
//--------------------------SET
public function setHost($host){
$this->host = $host;
}
public function setDbname($dbname){
$this->dbname = $dbname;
}
public function setPort($port){
$this->port = $port;
}
public function setUser($user){
$this->user = $user;
}
public function setPassword($password){
$this->password = $password;
}
//--------------------------------GET
public function getHost(){
return $this->host;
}
public function getDbname(){
return $this->dbname;
}
public function getPort(){
return $this->port;
}
public function getUser(){
return $this->user;
}
public function getPassword(){
return $this->password;
}
public function connect (){//public function connect (){
$db = new PDO( 'mysql:host='.getHost().
';dbname='.getDbname().
';port='.getPort(),getUser(),getPassword());
$query = $db->query('SELECT * FROM conta');
}
public function insert($email,$pwd){
$sql = "INSERT INTO conta (email,pass,dataCadastro) VALUES (?, ?, NOW() )";
$query = $db->prepare($sql);
$query->execute(array($email,$pwd));
}
}
?>
//----------------------- config.php----------------------------------
<?php
// $host = '127.0.0.1';
// $dbname = 'meuDb';
// $port = '3306';
// $user = 'root';
// $password = '';
DEFINE('HOST','127.0.0.1');
DEFINE('USER','root');
DEFINE('PASS','');
DEFINE('DB','meuDb');
DEFINE('TYPE','mysql');
DEFINE('PORT','3306');
$database = array("user"=>USER,"pass"=>PASS,"name"=>DB,"host"=>HOST,"type"=>TYPE,"port"=>PORT);
?>
//PROBLEM----------------------------------------------
It's appering this error, does anyone know why this is happening ?
Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-04-11 19:58 -0400 |
| Message-ID | <mgccee$uq3$1@dont-email.me> |
| In reply to | #15238 |
On 4/11/2015 7:18 PM, Hiago Vitor wrote: <snip code> > //PROBLEM---------------------------------------------- > It's appering this error, does anyone know why this is happening ? > > Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70 > > Maybe because there is no function getHost() (just a member function of a couple of classes by that name)? -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-11 17:12 -0700 |
| Message-ID | <9d9db962-c7e7-4aa9-bbe8-e0f8a7a5619c@googlegroups.com> |
| In reply to | #15239 |
Em sábado, 11 de abril de 2015 20:59:07 UTC-3, Jerry Stuckle escreveu: > On 4/11/2015 7:18 PM, Hiago Vitor wrote: > <snip code> > > > > //PROBLEM---------------------------------------------- > > It's appering this error, does anyone know why this is happening ? > > > > Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70 > > > > > > Maybe because there is no function getHost() (just a member function of > a couple of classes by that name)? > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > jstucklex@attglobal.net > ================== what's the difference of function and member function?
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-04-11 20:17 -0400 |
| Message-ID | <mgcdhu$25i$1@dont-email.me> |
| In reply to | #15240 |
On 4/11/2015 8:12 PM, Hiago Vitor wrote: > Em sábado, 11 de abril de 2015 20:59:07 UTC-3, Jerry Stuckle escreveu: >> On 4/11/2015 7:18 PM, Hiago Vitor wrote: >> <snip code> >> >> >>> //PROBLEM---------------------------------------------- >>> It's appering this error, does anyone know why this is happening ? >>> >>> Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70 >>> >>> >> >> Maybe because there is no function getHost() (just a member function of >> a couple of classes by that name)? >> > > what's the difference of function and member function? > A member function is a function that is part of a class. It must be called with an object of that class (unless it's a static member function - but don't worry about that right now) and is used to set/retrieve information from that object. My suggestion is for you to study up on object oriented programming; PHP is going that way (although not very well). -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-11 17:24 -0700 |
| Message-ID | <840a9236-b7cf-478f-af74-f7fe4e776811@googlegroups.com> |
| In reply to | #15241 |
Em sábado, 11 de abril de 2015 21:18:03 UTC-3, Jerry Stuckle escreveu: > On 4/11/2015 8:12 PM, Hiago Vitor wrote: > > Em sábado, 11 de abril de 2015 20:59:07 UTC-3, Jerry Stuckle escreveu: > >> On 4/11/2015 7:18 PM, Hiago Vitor wrote: > >> <snip code> > >> > >> > >>> //PROBLEM---------------------------------------------- > >>> It's appering this error, does anyone know why this is happening ? > >>> > >>> Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70 > >>> > >>> > >> > >> Maybe because there is no function getHost() (just a member function of > >> a couple of classes by that name)? > >> > > > > what's the difference of function and member function? > > > > A member function is a function that is part of a class. It must be > called with an object of that class (unless it's a static member > function - but don't worry about that right now) and is used to > set/retrieve information from that object. > > My suggestion is for you to study up on object oriented programming; PHP > is going that way (although not very well). > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > jstucklex@attglobal.net > ================== thanks, i found that if use this->getHost() . I've studied OOP but sometimes I have some problems I will try to find a good book on OOP to learn more.
[toc] | [prev] | [next] | [standalone]
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-11 17:26 -0700 |
| Message-ID | <329bc823-08f6-44fe-a275-381c34d04f11@googlegroups.com> |
| In reply to | #15241 |
Em sábado, 11 de abril de 2015 21:18:03 UTC-3, Jerry Stuckle escreveu: > On 4/11/2015 8:12 PM, Hiago Vitor wrote: > > Em sábado, 11 de abril de 2015 20:59:07 UTC-3, Jerry Stuckle escreveu: > >> On 4/11/2015 7:18 PM, Hiago Vitor wrote: > >> <snip code> > >> > >> > >>> //PROBLEM---------------------------------------------- > >>> It's appering this error, does anyone know why this is happening ? > >>> > >>> Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70 > >>> > >>> > >> > >> Maybe because there is no function getHost() (just a member function of > >> a couple of classes by that name)? > >> > > > > what's the difference of function and member function? > > > > A member function is a function that is part of a class. It must be > called with an object of that class (unless it's a static member > function - but don't worry about that right now) and is used to > set/retrieve information from that object. > > My suggestion is for you to study up on object oriented programming; PHP > is going that way (although not very well). > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > jstucklex@attglobal.net > ================== thanks, i found that if use this->getHost() work. I've studied OOP but sometimes I have some problems I will try to find a good book of OOP to learn more.
[toc] | [prev] | [next] | [standalone]
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-12 06:01 -0700 |
| Message-ID | <ced25579-ca73-4434-9af3-8d9431790398@googlegroups.com> |
| In reply to | #15238 |
Em sábado, 11 de abril de 2015 20:18:36 UTC-3, Hiago Vitor escreveu:
> //-----------------index.php---------------------------------
>
> <?php
> include 'db.php';
> include 'config.php';
>
> $Data = new DataBase($database);
> //$Data = new DataBase($host,$dbname,$port,$user,$password);
>
> $Data->email = 'testes$gmail.com';
> $Data->senha = 'teste5';
>
> echo $Data->getHost().'<br>';
> echo $Data->getDbname().'<br>';
> echo $Data->getPort().'<br>';
> echo $Data->getUser().'<br>';
> echo $Data->getPassword().'<br>';
> $Data->connect();
>
>
> $email='lalaal@gmail.com';
> $pwd='lalalalalala';
> $Data->insert($email,$pwd);
>
> ?>
>
> //-------------------------------db.php--------------------------------
>
> <?php
>
> class DataBase{
> public $email;
> public $senha;
>
> public $host;
> public $dbname;
> public $port;
> public $user;
> public $password;
> //var $type;
>
> public function __construct($database){
> self::setHost($database['host']);
> self::setDbname($database['name']);
> self::setPort($database['port']);
> self::setUser($database['user']);
> self::setPassword($database['pass']);
> //---- self::set_type($database['type']);
> }
>
> //--------------------------SET
>
> public function setHost($host){
> $this->host = $host;
> }
>
> public function setDbname($dbname){
> $this->dbname = $dbname;
> }
>
> public function setPort($port){
> $this->port = $port;
> }
>
> public function setUser($user){
> $this->user = $user;
> }
>
> public function setPassword($password){
> $this->password = $password;
> }
>
> //--------------------------------GET
>
> public function getHost(){
> return $this->host;
> }
>
> public function getDbname(){
> return $this->dbname;
> }
>
> public function getPort(){
> return $this->port;
> }
>
> public function getUser(){
> return $this->user;
> }
>
> public function getPassword(){
> return $this->password;
> }
>
> public function connect (){//public function connect (){
> $db = new PDO( 'mysql:host='.getHost().
> ';dbname='.getDbname().
> ';port='.getPort(),getUser(),getPassword());
> $query = $db->query('SELECT * FROM conta');
> }
>
> public function insert($email,$pwd){
> $sql = "INSERT INTO conta (email,pass,dataCadastro) VALUES (?, ?, NOW() )";
> $query = $db->prepare($sql);
> $query->execute(array($email,$pwd));
> }
> }
> ?>
>
> //----------------------- config.php----------------------------------
> <?php
> // $host = '127.0.0.1';
> // $dbname = 'meuDb';
> // $port = '3306';
> // $user = 'root';
> // $password = '';
>
> DEFINE('HOST','127.0.0.1');
> DEFINE('USER','root');
> DEFINE('PASS','');
> DEFINE('DB','meuDb');
> DEFINE('TYPE','mysql');
> DEFINE('PORT','3306');
>
> $database = array("user"=>USER,"pass"=>PASS,"name"=>DB,"host"=>HOST,"type"=>TYPE,"port"=>PORT);
>
> ?>
> //PROBLEM----------------------------------------------
> It's appering this error, does anyone know why this is happening ?
>
> Fatal error: Call to undefined function getHost() in /opt/lampp/htdocs/testedb/db.php on line 70
-------connect-------
public function connect (){
try{
$db = new PDO( 'mysql:host='.$this->getHost().
';dbname='.$this->getDbname().
';port='.$this->getPort(),$this->getUser(),$this->getPassword());
return $db;
}
catch(EXCEPTION $e){
echo 'Error: ' . $e->getMessage();
}
}
----------------update--------
public function update($email,$pwd,$id){
try {
$sql = "UPDATE conta SET email= ? , pass= ? WHERE id(pk)= ? ";
$query = $this->connect()->prepare($sql);
$query->execute(array($email, $pwd, $id));
}
catch(PDOException $e) {
echo 'Error: ' . $e->getMessage();
}
}
----------new problem---------
I hava another problem now update dont work, but no erros appear
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-04-12 12:40 -0400 |
| Message-ID | <mge74h$ohd$1@dont-email.me> |
| In reply to | #15248 |
On 4/12/2015 9:01 AM, Hiago Vitor wrote:
<snip unrelated code>
>
> -------connect-------
>
> public function connect (){
> try{
> $db = new PDO( 'mysql:host='.$this->getHost().
> ';dbname='.$this->getDbname().
> ';port='.$this->getPort(),$this->getUser(),$this->getPassword());
> return $db;
> }
> catch(EXCEPTION $e){
> echo 'Error: ' . $e->getMessage();
> }
> }
> ----------------update--------
>
> public function update($email,$pwd,$id){
> try {
> $sql = "UPDATE conta SET email= ? , pass= ? WHERE id(pk)= ? ";
> $query = $this->connect()->prepare($sql);
> $query->execute(array($email, $pwd, $id));
> }
> catch(PDOException $e) {
> echo 'Error: ' . $e->getMessage();
> }
> }
> ----------new problem---------
> I hava another problem now update dont work, but no erros appear
>
You're not checking the return value from your $query->execute()
statement. I suspect you have an error in your SQL statement, and it
doesn't look like PDOStatement::execute() throws an exception (I don't
use PDO, so all I can go from is the doc).
I suspect your problem is in your WHERE clause - what is 'id(pk)'
supposed to be? Are you trying to identify the column 'id' as a primary
key? That would be unnecessary (and illegal here).
Check the return value from your $query->execute() call, and if it's
false, call $query->errorInfo() to get the error information.
P.S. You have a couple of basic logic faults in your code here, also.
When you catch an exception, the correct way to handle it is to either
correct the error or skip any processing which depends on the call
completing.
In your connect() function, you catch the exception but only display an
error message. Then you just return from the function, with no return
value. This is your first problem - the result of trying to use the
return value from connect() when it fails is undefined.
The other problem is in your update() function, you're just assuming the
connect() function works. Since you caught any possible exception in
connect(), you won't see another exception from a connection failure.
The easiest way to correct this is to just not catch the exception in
connect(). Then it will get caught in update(), and processing will
stop (you'll get the error message from the catch block here).
Other possibilities include rethrowing the error (not good because
you're really not doing anything with the error in connect()) or
returning false from connect() and testing the return value in update()
before trying to use it.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-12 10:03 -0700 |
| Message-ID | <3080b89d-ca71-4aeb-acd3-fae272ccf6c4@googlegroups.com> |
| In reply to | #15253 |
Em domingo, 12 de abril de 2015 13:40:48 UTC-3, Jerry Stuckle escreveu:
> On 4/12/2015 9:01 AM, Hiago Vitor wrote:
> <snip unrelated code>
> >
> > -------connect-------
> >
> > public function connect (){
> > try{
> > $db = new PDO( 'mysql:host='.$this->getHost().
> > ';dbname='.$this->getDbname().
> > ';port='.$this->getPort(),$this->getUser(),$this->getPassword());
> > return $db;
> > }
> > catch(EXCEPTION $e){
> > echo 'Error: ' . $e->getMessage();
> > }
> > }
> > ----------------update--------
> >
> > public function update($email,$pwd,$id){
> > try {
> > $sql = "UPDATE conta SET email= ? , pass= ? WHERE id(pk)= ? ";
> > $query = $this->connect()->prepare($sql);
> > $query->execute(array($email, $pwd, $id));
> > }
> > catch(PDOException $e) {
> > echo 'Error: ' . $e->getMessage();
> > }
> > }
> > ----------new problem---------
> > I hava another problem now update dont work, but no erros appear
> >
>
> You're not checking the return value from your $query->execute()
> statement. I suspect you have an error in your SQL statement, and it
> doesn't look like PDOStatement::execute() throws an exception (I don't
> use PDO, so all I can go from is the doc).
>
> I suspect your problem is in your WHERE clause - what is 'id(pk)'
> supposed to be? Are you trying to identify the column 'id' as a primary
> key? That would be unnecessary (and illegal here).
>
> Check the return value from your $query->execute() call, and if it's
> false, call $query->errorInfo() to get the error information.
>
> P.S. You have a couple of basic logic faults in your code here, also.
> When you catch an exception, the correct way to handle it is to either
> correct the error or skip any processing which depends on the call
> completing.
>
> In your connect() function, you catch the exception but only display an
> error message. Then you just return from the function, with no return
> value. This is your first problem - the result of trying to use the
> return value from connect() when it fails is undefined.
>
> The other problem is in your update() function, you're just assuming the
> connect() function works. Since you caught any possible exception in
> connect(), you won't see another exception from a connection failure.
>
> The easiest way to correct this is to just not catch the exception in
> connect(). Then it will get caught in update(), and processing will
> stop (you'll get the error message from the catch block here).
>
> Other possibilities include rethrowing the error (not good because
> you're really not doing anything with the error in connect()) or
> returning false from connect() and testing the return value in update()
> before trying to use it.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================
I can insert, select etc but only update dont work(than connect is working), "id(pk)" is the primary key( "id(pk)") . That's why i dont uderstand updat not working
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-04-12 16:34 -0400 |
| Message-ID | <mgekq6$f0m$2@dont-email.me> |
| In reply to | #15254 |
On 4/12/2015 1:03 PM, Hiago Vitor wrote:
> Em domingo, 12 de abril de 2015 13:40:48 UTC-3, Jerry Stuckle escreveu:
>> On 4/12/2015 9:01 AM, Hiago Vitor wrote:
>> <snip unrelated code>
>>>
>>> -------connect-------
>>>
>>> public function connect (){
>>> try{
>>> $db = new PDO( 'mysql:host='.$this->getHost().
>>> ';dbname='.$this->getDbname().
>>> ';port='.$this->getPort(),$this->getUser(),$this->getPassword());
>>> return $db;
>>> }
>>> catch(EXCEPTION $e){
>>> echo 'Error: ' . $e->getMessage();
>>> }
>>> }
>>> ----------------update--------
>>>
>>> public function update($email,$pwd,$id){
>>> try {
>>> $sql = "UPDATE conta SET email= ? , pass= ? WHERE id(pk)= ? ";
>>> $query = $this->connect()->prepare($sql);
>>> $query->execute(array($email, $pwd, $id));
>>> }
>>> catch(PDOException $e) {
>>> echo 'Error: ' . $e->getMessage();
>>> }
>>> }
>>> ----------new problem---------
>>> I hava another problem now update dont work, but no erros appear
>>>
>>
>> You're not checking the return value from your $query->execute()
>> statement. I suspect you have an error in your SQL statement, and it
>> doesn't look like PDOStatement::execute() throws an exception (I don't
>> use PDO, so all I can go from is the doc).
>>
>> I suspect your problem is in your WHERE clause - what is 'id(pk)'
>> supposed to be? Are you trying to identify the column 'id' as a primary
>> key? That would be unnecessary (and illegal here).
>>
>> Check the return value from your $query->execute() call, and if it's
>> false, call $query->errorInfo() to get the error information.
>>
>> P.S. You have a couple of basic logic faults in your code here, also.
>> When you catch an exception, the correct way to handle it is to either
>> correct the error or skip any processing which depends on the call
>> completing.
>>
>> In your connect() function, you catch the exception but only display an
>> error message. Then you just return from the function, with no return
>> value. This is your first problem - the result of trying to use the
>> return value from connect() when it fails is undefined.
>>
>> The other problem is in your update() function, you're just assuming the
>> connect() function works. Since you caught any possible exception in
>> connect(), you won't see another exception from a connection failure.
>>
>> The easiest way to correct this is to just not catch the exception in
>> connect(). Then it will get caught in update(), and processing will
>> stop (you'll get the error message from the catch block here).
>>
>> Other possibilities include rethrowing the error (not good because
>> you're really not doing anything with the error in connect()) or
>> returning false from connect() and testing the return value in update()
>> before trying to use it.
>>
>
> I can insert, select etc but only update dont work(than connect is working), "id(pk)" is the primary key( "id(pk)") . That's why i dont uderstand updat not working
>
Your column name is "id(pk)"? This column name is invalid in most
databases.
Did you check the result of your execute() call like I suggested?
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Hiago Vitor <hiagoiuri@gmail.com> |
|---|---|
| Date | 2015-04-13 12:48 -0700 |
| Message-ID | <05d2e4dd-27eb-4138-8b52-28c22ed59404@googlegroups.com> |
| In reply to | #15256 |
Em domingo, 12 de abril de 2015 17:34:16 UTC-3, Jerry Stuckle escreveu:
> On 4/12/2015 1:03 PM, Hiago Vitor wrote:
> > Em domingo, 12 de abril de 2015 13:40:48 UTC-3, Jerry Stuckle escreveu:
> >> On 4/12/2015 9:01 AM, Hiago Vitor wrote:
> >> <snip unrelated code>
> >>>
> >>> -------connect-------
> >>>
> >>> public function connect (){
> >>> try{
> >>> $db = new PDO( 'mysql:host='.$this->getHost().
> >>> ';dbname='.$this->getDbname().
> >>> ';port='.$this->getPort(),$this->getUser(),$this->getPassword());
> >>> return $db;
> >>> }
> >>> catch(EXCEPTION $e){
> >>> echo 'Error: ' . $e->getMessage();
> >>> }
> >>> }
> >>> ----------------update--------
> >>>
> >>> public function update($email,$pwd,$id){
> >>> try {
> >>> $sql = "UPDATE conta SET email= ? , pass= ? WHERE id(pk)= ? ";
> >>> $query = $this->connect()->prepare($sql);
> >>> $query->execute(array($email, $pwd, $id));
> >>> }
> >>> catch(PDOException $e) {
> >>> echo 'Error: ' . $e->getMessage();
> >>> }
> >>> }
> >>> ----------new problem---------
> >>> I hava another problem now update dont work, but no erros appear
> >>>
> >>
> >> You're not checking the return value from your $query->execute()
> >> statement. I suspect you have an error in your SQL statement, and it
> >> doesn't look like PDOStatement::execute() throws an exception (I don't
> >> use PDO, so all I can go from is the doc).
> >>
> >> I suspect your problem is in your WHERE clause - what is 'id(pk)'
> >> supposed to be? Are you trying to identify the column 'id' as a primary
> >> key? That would be unnecessary (and illegal here).
> >>
> >> Check the return value from your $query->execute() call, and if it's
> >> false, call $query->errorInfo() to get the error information.
> >>
> >> P.S. You have a couple of basic logic faults in your code here, also.
> >> When you catch an exception, the correct way to handle it is to either
> >> correct the error or skip any processing which depends on the call
> >> completing.
> >>
> >> In your connect() function, you catch the exception but only display an
> >> error message. Then you just return from the function, with no return
> >> value. This is your first problem - the result of trying to use the
> >> return value from connect() when it fails is undefined.
> >>
> >> The other problem is in your update() function, you're just assuming the
> >> connect() function works. Since you caught any possible exception in
> >> connect(), you won't see another exception from a connection failure.
> >>
> >> The easiest way to correct this is to just not catch the exception in
> >> connect(). Then it will get caught in update(), and processing will
> >> stop (you'll get the error message from the catch block here).
> >>
> >> Other possibilities include rethrowing the error (not good because
> >> you're really not doing anything with the error in connect()) or
> >> returning false from connect() and testing the return value in update()
> >> before trying to use it.
> >>
> >
> > I can insert, select etc but only update dont work(than connect is working), "id(pk)" is the primary key( "id(pk)") . That's why i dont uderstand updat not working
> >
>
> Your column name is "id(pk)"? This column name is invalid in most
> databases.
>
> Did you check the result of your execute() call like I suggested?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================
i change the id(pk) to id like u said, than i start using:
$query->bindParam(':id', $id, PDO::PARAM_INT);
because i read that standard would be "PDO::PARAM_STR" that's why i couldn't sent the id, now everything works. Thx for the tip about the id(pk).
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web