[thelist] merging a dictionary to sql table

Chris Dorer cdorer at gmail.com
Wed Nov 16 07:35:25 CST 2005


My personal favorite is to use Pear::DB for DB anything because :
http://pear.php.net/manual/en/package.database.db.intro-execute.php

Prepare and Execute, prepare readies the SQL string.
Execute runs the prepared query, adding necessary backslashes automatically.

> $a_values = array();
>
 $a_values[] = $_POST['name'];
> $a_values[] = $_POST['address'];
> $a_values[] = $_POST['city'];
> $a_values[] = $_POST['state'];
> $a_values[] = $_POST['zip'];
> $a_values[] = $_POST['phone'];
> $a_values[] = $_POST['email'];
> $a_values[] = $_POST['interest'];
> $a_values[] = $_POST['status'];


 INSERT INTO
> contacts
> SET
> name = ?,
> address = ?,
> city = ?,
> state = ?,
> zip = ?,
> phone = ?,
> email = ?,
> interest = ?,
> status = ?
> ";


 $qh = $o_db->prepare( $sql );
> $o_res = $o_db->execute( $qh, $a_values );
> if( DB::isError( $o_res ) ) {
> //**FIXME add error handling
> //echo '<pre>'.print_r( $o_res, 1 ).'</pre>';
> //exit;
> //return false;
> } elseif( $o_res->numRows() > 0 ) { }
>


Cheers


On 11/16/05, Matt Warden <mwarden at gmail.com> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Alex Beston wrote:
> > Hi
> >
> > ok found the problem
> >
> > abbey
> > abbey's
> > abbeys
> > abbot
> >
> > when it gets to abbey's it doesnt like that ' in the keyword. i take it
> > i would escape it with a \ or even better remove all that have an
> > apostrophe since what sort of dictionary should have apostrophed words?
>
> http://us3.php.net/addslashes
>
> - --
> Matt Warden
> Miami University
> Oxford, OH, USA
> http://mattwarden.com
>
>
> This email proudly and graciously contributes to entropy.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
> iD8DBQFDevCPrI3LObhzHRMRAj8SAKDJ/iN5Y0xz8XgkTm6YMfYUjbcYjwCfX7oU
> sh902ewlwjERl1zqZBffw48=
> =eLch
> -----END PGP SIGNATURE-----
> --
>
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>



More information about the thelist mailing list