I'm using jqGrid and I would like to convert from mysql statements to PDO (PHP Data Objects) but when I convert the statements to PDO the data doesn't display in the grid but I know that the scripts are retrieving data. I looked at the trirand demos (click on 'Loading Data' then JSON data) and it gives examples with the deprecated mysql statements. I am unable to find a lot of resources that aid in the conversion from mysql to PDO for jqGrid.
So the next thing I did was compare the FORMAT of the two sets of outputted data (mysql and PDO).
Here is the mysql formatted data (Output):
{"rows":[["01","3701","37010100","37010102","37A","01","Executive Offices","SEC","Office of the Secretary","Y"], etc...]}
Then the PDO formatted data (Output):
[{"unit_id":"01","div_id":"3701","org_code":"37010100","l1l2_id":"37010102","CSA_id":"37A","area_id":"01","long_desc":"Executive Offices","short_desc":"SEC","unit_desc":"Office of the Secretary","avail_ind":"Y"}]
I think that the reason why jqGrid is not display the data in the grid is because it's not accepting the PDO format of the data. But I don't know how to format the PDO data to simulate the format that the mysql format. What should I do?
Thanks in advance.
I found this post and it suggested changing echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC)); to echo json_encode($stmt->fetchAll(PDO::FETCH_NUM)); and it formatted the data correctly so jqGrid could display the data.
Related
Sorry my english is not good.
I have problem with to display data format "geometry" from mysql database. I got the data from file extension .geojson (like json but but contains coordinate), I convert the .geojson data with cmd. and this data is formed.
for example my geojson data
and this is an example of converting geojson to database
i use laravel, to display this data what is the task of laravel or mysql (eg there is a special mysql function)? and how?
What are you looking to do with the geometry data and have you looked at the Geo JSON functions https://dev.mysql.com/doc/refman/8.0/en/spatial-geojson-functions.html such as St+GeomFromJson()??
So i wanted to save some tags data to the database from the UI form,
Tags: ["male","female","kids"]
I tried everything like but it saves as a string, ialso tried checking if i can alter the data type to array in mysql, or json but i got this
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JSON(255) NOT NULL' at line 1
I also tried json_encode and json_decode() but still no head so please what can i do?
There isn't any data type as JSON or Array in DB.
What you can do is use the tags field as TEXT as told by #Rick James and then encode your input as json by using json_encode() method before inserting and decode it after retrieving the data from DB by using json_decode() method.
JSON is basically a minimal, readable format for structuring data. Which means it can be considered as a String.
Here is a good post about JSON, in case you need.
What is JSON?
There is no datatype called JSON. Instead use TEXT without the (255).
I have json files, volume is approx 500 TB. I have loaded complete set into hive data warehouse.
How would I validate or test the data that was loaded into hive warehouse. What should be my testing strategy ?
Client want us to validate the json data. Whether the data loaded into hive is correct ot not. Is there any miss? If yes, which field it was?
Please help.
How is your data being stored in hive tables ?
One option is create a Hive UDF function that receive the JSON string and validate the data and return another string with the error message or an empty string if the JSON string is well formed.
Here is a Hve UDF tutorial: http://blog.matthewrathbone.com/2013/08/10/guide-to-writing-hive-udfs.html
With the Hive UDF function in place you can executequeries like:
select strjson, validateJson(strjson) from jsonTable where validateJson(strjson) != "";
We have stored an XML file in the database as blob field. Now we would like to see the data in the SQL editor.
SELECT CAST(response AS CHAR(10000)) FROM response_table
we see the column as ???
Could someone help me on how to get the values in the readable format?
Thanks.
It depends on your editor to show the blob response. I use Toad for mySql. Which shows the response and I can view it in different formats like HEX, ASC11 etc. Your query will remain same, not casting is needed.
SELECT response FROM response_table
I am exporting a csv file in to mysql db using load data infile syntax.
the date in csv is in 2009/10/31 7:8:57.0 format. Is there any way to convert this while loading to something like 2009-10-31 07:08:57 ?
Execute TO_CHAR(TO_DATE(datefromcsv, 'YYYY/MM/DD HH:MI:SS.FF'), 'YYYY-MM-DD HH:MI:SS') when you are doing the INSERT into the db.
(usual caveats apply here) A regular expression might be what you need. Substitute / with - and remove the trailing .0.
I am surprised, though, that mysql can't handle dates like the one you provided. See for example the mySql manual. Have you tried feeding it to mysql and seeing what happens?