Sunday, 15 January 2012

php - OOPHP MySQLi Parameterized Query not working? -


I am trying to create this work for a few days. I want to develop my knowledge about PHP and database security and looking to use OOPH and Powered Queries. I thought I would just start by connecting to the database and selecting and displaying the results. I know that paramerized queries work on themselves, but when I put it in a class and call it, it will not get results and will not display them. This is my code I'm working on:

  & lt ;? Php class connect {public static function run () {$ mysqli = new mysqli ("*****", "*****", "*****"); $ Db = "sale"; Mysqli_select_db ($ Database); If (! $ Mysqli) {printf ("Connection failed:% s \ n", mysqli_connect_error ()); } Else {echo ("Maria DB Connection Successful !!!"); }}} // call_user_func (array ($ classname, 'run')); Class contacts {Select Public Function () (if ($ stmt = $ mysqli- & gt; Prepare ("Select consensus_ID, Con_fanny, contact with Kondi_LMM, Conmark")) Execute {$ stmt- & gt;; $ Stmt- & gt; bind_result ($ id, $ fname, $ lname, $ email); echo ("& lt; table alignment = 'center' width = '40% '"); echo ("& lt; tr & gt; ;); Echo ("& lt; td align = 'center' width = '25% '& gt; contact id & lt; / td & gt;"); echo (" fetch Echo ("& lt; tr & gt;"); echo ("& lt; TD alignment = 'center' width = '25% '& gt;"); printf ("% s", $ this- & Echo ("& lt; TD alignment = 'center' width = '25% '& gt;"); printf ("% s" , $ This-> $ fname); echo (""); Echo ("& lt; td alignment = 'center' width = '25% '& gt;"); Printf ("% s", $ this- & gt; $ lname); Echo ("& lt; / td>"); Echo ("& lt; td alignment = 'center' width = '25% '& gt;"); Printf ("% s", $ this- & gt; $ email); Echo ("& lt; / td>"); Echo ("& lt; / tr & gt;"); } Printf ("& lt; / table & gt;"); $ Stmt- & gt; near (); } Other {printf ("Ready statement error:% s \ n", $ mysqli-> Error ()); }} Connect = "connect"; $ Connect :: runs (); $ Contact = "Contact"; $ Contact select: (); ? & Gt;   

When I run the page, only the output I get is "Maria DB connection successful !!!", but this class does not seem to run in selection () within "Contacts" it happens . I want to learn better ways of coding with PHP, so if there is a better way, I would love to learn it!

I would be very grateful for any help that anyone can give.

There are two major problems with your code

  1. You are using mysqli instead, making your goal ten times harder.
  2. You are trying to get everyone together. There is no way to know that you have to open the API Try to get acquainted with it, just run a few questions using plain text code. Then combine these codes into the work and then start for the class.

No comments:

Post a Comment