[PHP] Insert Symbol into Mysql

2009-09-16 Thread Samrat Kar
I want to insert symbols like degree, plusminus, currency along with string
into Mysql database. Front is HTML form with javascript. Server side scripts
are written in PHP. Please help.

 

Regards,

 

Samrat Kar



RE: [PHP] NULLS vs Empty result in PHP

2009-09-23 Thread Samrat Kar
Use var_dump before processing your result.

Regards,

Samrat Kar
FRD, BARC

Tel: 022-25597295
Alternate Email: esam...@yahoo.com


-Original Message-
From: Dan Shirah [mailto:mrsqua...@gmail.com] 
Sent: Wednesday, September 23, 2009 5:28 PM
To: PHP General
Subject: [PHP] NULLS vs Empty result in PHP

Morning!

Just a quick question.

Say I have a column in my database that could contain NULLS, empty spaces,
or an actual value.

If I do:

$my_query = "SELECT my_column FROM my_database WHERE 1 = 1";
$my_result = ifx_query($my_query, $connect_id);

while($row = ifx_fetch_row($my_result)) {
  $my_column = trim($row['my_column']);

  if ($my_column != "") {
   echo "Test";
  }
}

The way PHP assigns the query results to the $my_column variable, wouldn't;
if ($my_column != "")  not do anything for the rows that contained NULLS or
empty spaces?

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.409 / Virus Database: 270.13.112/2388 - Release Date: 09/22/09
17:54:00



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Stricter Error Checking?

2009-09-23 Thread Samrat Kar
Better use mysqli rather mysql. It supports all new features of MySQL.

I solved the problem in following manner.

1. Detect the return value of mysqli->query function.
2. If it is FALSE get the error no, error msg etc and store in a Mysql table
for further review. You can also write it in a error log file.

Example...

/* Part of MYSQLI class */

public function Query($sql, $flag = 0) {
$my = new mysqli($this->host,$this->user,$this->pass,$this->db);
if(mysqli_connect_errno()) {
   $this->conn_err_no = mysqli_connect_errno();
   $this->conn_err_msg = mysqli_connect_error();
   return FALSE;
}
//$this->QueryLog(addslashes($sql));
$arr1 = explode(" ", $sql);
$queryType = $arr1[0];
$result = $my->query($sql);
if($result === FALSE) {
$this->query_err_no = $my->errno;
$this->query_err_msg = $my->error;
$this->sqlstate = $my->sqlstate;
$this->ErrorLog(addslashes($sql));
}
else {
$this->QueryLog(addslashes($sql));
}

if($queryType == "SELECT" || $queryType == "SHOW" || $queryType ==
"DESCRIBE" || $queryType == "EXPLAIN" || $queryType == "CALL") {
if($result) {
$num_row = $result->num_rows;
$num_col = $result->field_count;
if($num_row == 0)
$ret = NULL;
if($num_row == 1 && $num_col == 1) {
$record = $result->fetch_row();
if($flag == 1) 
 $ret = array($record[0]);
else
 $ret = $record[0];
}
if($num_row == 1 && $num_col > 1) {
if($flag == 1)
 $ret = array($result->fetch_array());
else
 $ret = $result->fetch_row();
}
if($num_row > 1 && $num_col == 1) {
$retarr = array();
while($record = $result->fetch_array()) {
array_push($retarr, $record[0]);
}
$ret = $retarr;
}
if($num_row > 1 && $num_col > 1) {
$retarr = array();
while($record = $result->fetch_array()) {
array_push($retarr, $record);
}
$ret = $retarr;
}
if($num_row > 0) {
$this->field_list = $result->fetch_fields();
}
}
else {
return FALSE;
}
}
else {
if($result === FALSE)
return FALSE;
if($queryType == "UPDATE" || $queryType == "INSERT" ||
$queryType == "REPLACE" || $queryType == "DELETE") {
$ret = $my->affected_rows;
if($queryType == "INSERT")
$this->last_insert_id = $my->insert_id;
}
}

return $ret;
}

private function QueryLog($query) {
$my = new mysqli($this->host,$this->user,$this->pass,$this->db);
if(mysqli_connect_errno()) {
   $this->conn_err_no = mysqli_connect_errno();
   $this->conn_err_msg = mysqli_connect_error();
   return FALSE;
}
$ts = time();
$sql = "INSERT INTO pi_global.tblquerylog
VALUES('','$ts','$query')";
$my->query($sql);
$my->close();
}

private function ErrorLog($query) {
$my = new mysqli($this->host,$this->user,$this->pass,$this->db);
if(mysqli_connect_errno()) {
   $this->conn_err_no = mysqli_connect_errno();
   $this->conn_err_msg = mysqli_connect_error();
   return FALSE;
    }
    $ts = time();
$errno = $this->query_err_no;
$errmsg = addslashes($this->query_err_msg);
$state = $this->sqlstate;
$sql = "INSERT INTO pi_global.tblerrorlog
VALUES('','$ts','$query','$errno','$errmsg','$state')";
$my->query($sql);
$my->close();
}

Regards,

Samrat Kar
FRD, BARC

Tel: 022-25597295
Alternate Email: esam...@yahoo.com

-Original Message-
From: Tim Legg [mailto:kc0...@yahoo.com] 
Sent: Wednesday, September 23, 2009 11:42 PM
To: php-general@lists.php.net
Subject: [PHP] Stricter Error Checking?

Hello,

I just spent way, way to much time trying to debug code due to a misnamed
element.  Here is a simplified example of the

RE: [PHP] how call a variable in a text

2009-10-21 Thread Samrat Kar
This is always safe to use variables like this...

$text = "This is " . $variable;

Or

$text = "This is " . $variable[0];

Regards,

Samrat Kar
FRD, BARC

Tel: 022-25597295
Alternate Email: esam...@yahoo.com


-Original Message-
From: Kim Madsen [mailto:php@emax.dk] 
Sent: Thursday, October 22, 2009 2:25 AM
To: a...@ashleysheridan.co.uk
Cc: David Murphy; php-general@lists.php.net
Subject: Re: [PHP] how call a variable in a text

Ashley Sheridan wrote on 2009-10-21 22:43:

> The {} only become really useful when you're trying to reference arrays
> within a string:
> 
> $var = array('great', 'boring');
> 
> $text = "this is {$var[0]}.";
> 
> Without the curly braces, PHP wouldn't be able to figure out whether you
> wanted the end string to be 'This is great.' or 'This is [0].' despite
> the variable itself clearly being an array.

Ehh what? This has never been a problem for me:

$text = "this is $var[0].";

However this does give an error (or notice, don't recall, haven't seen 
the error in quite a while):

$text = "this is $var['0'].";

In that case the solution is the curly brackets:

$text = "this is {$var['0']}.";

-- 
Kind regards
Kim Emax - masterminds.dk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.423 / Virus Database: 270.14.25/2450 - Release Date: 10/21/09
16:44:00



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php