php - Using PDO to create a mysql query function, wont insert rows -
I'm trying to try using PDOs, and I'm using some pre-built functions to help simplify things when I want to do a query, first joins one, runs another query .
Unfortunately this will not let me insert rows using the dbiquity (). Selecting works fine, just can not find anything else to work
Here is the code:
function dbConnect () {global $ dbh; $ DbInfo ['database_target'] = "localhost"; $ DbInfo ['database_name'] = "mescalcaster"; $ DbInfo ['username'] = "root"; $ DbInfo ['password'] = "password"; $ DbConnString = "mysql: host =" $ DbInfo ['database_target'] "]; dbname =" $ DbInfo ['Database_Name']; $ Dbh = New PDO ($ dbConnString, $ dbInfo ['username]', $ dbInfo ['password']); $ Dbh- & gt; Set Attribution (PDO :: ATTRRAMOD, PDO :: ERRMODDEXEPEPS); $ Error = $ dbh- & gt; Errorinfo (); If ($ error [0]! = "") {Print "& lt; p & gt; Database connection error: "; Print_r ($ error); }} Function dbQuery ($ queryString) {global $ dbh; $ Query = $ dbh- & gt; Query ($ queryString); $ I = 0; Forex Currency ($ query $ query2) {$ query returns [$ i] = $ query2; $ I ++; } If ($ i> 1) {Return $ queryReturn; } And {return the $ query return [0]; }}
Only works with queries that result set (for example To view INSERT / UPDATE / DELETE If you are going to enter the data provided by the user in your DBMS, then I have the functionality of the prepared statement of the PDO I suggest suggesting automatic escape to prevent SQL injection. For example, / P> SELECT