I'm using str_replace in a class that I'm attemtping to use for database access. I'm having a strange problem though and it seems to be the str_replace function that causes the problem. Here's the code:
function execute() {
$binds = func_get_args();print_r($binds);
foreach($binds as $index => $name) {
$this->binds[$index + 1] = $name;
}
$cnt = count($binds);
$query = $this->query;
foreach ($this->binds as $ph => $pv) {
$query = str_replace(":$ph", "'".mysql_escape_string($pv)."'", $query);
echo '('.$ph ." => ". $pv. ')';
}
echo '<br><br>'.$query;
$this->result = mysql_query($query, $this->dbh);
if(!$this->result) {
echo "database query did not work";
}
return $this;
And here is the output that the $query shoes after being processed by str_replace:
INSERT INTO customers (first_name, last_name, company, email, address, city, state_id, country_id, postal_code, prim_phone, alt_phone, referal, status, desc) VALUES('', 'Fred', 'Smith', 'Joes smokes and more', 'joe@home.net', '222 n. south st.', 'Phoenix', '1', '4', ''0, ''1, ''2, ''3, ''4)
The last 4 fields are not being replaced. These are being skipped by str_replace. Any suggestions?