Is there a better, more “Standard” way to perform SQL queries in PHP without using a framework?

前端 未结 8 981
借酒劲吻你
借酒劲吻你 2021-01-27 09:02

For the longest time, I\'ve been using the following basic formatting for SQL queries within my PHP:

$sql = \"SELECT * FROM `user-data` WHERE `id` = \'\".$id.\"\         


        
8条回答
  •  盖世英雄少女心
    2021-01-27 09:19

    There is MDB_QueryTool I never tried.

    IMHO Zend_DB is really cool, the zend framework allow you to use only the part you are interested in so you might want to take it a look event if you don't want the full framework.

    what I like in Zend_DB is the table select syntax

    $userRowset = $user->fetchAll( $user->select()
     ->where('name LIKE ?', $name . '%')
     ->order('id ASC')
     ->limit(10) 
    );
    

    You can easily see all the criterias and table involved so I find better then doing plain SQL. Just one warning Zend_DB doesn't handle all the SQL, so time to time you would have to write plain SQL but that's really rare.

提交回复
热议问题